{include file="public/layout.htm" /}
<body class="back-c">
    <div class="ey-content">
        <div class="nav-tab-block">
            <div class="tab-wrap">
                <div class="tab-item active">基础信息</div>
                <div class="tab-item ">财务信息</div>
                <div class="tab-item ">订单信息</div>
            </div>
        </div>

        <div class="item-wrap-box" style="display: block;">
            <div class="item-wrap">
                <form id="postForm">
                    {:token('__token_users_edit__')}
                    <input type="hidden" name="type" value="3">
                    <input type="hidden" name="_ajax" value="1">
                    <input type="hidden" name="weappAjax" value="1">
                    <input type="hidden" name="users_id" value="{$info.users_id}">
                    <input type="hidden" name="coin" id="coin" value="{$info.coin}">
                    <input type="hidden" name="is_lock" id="is_lock" value="{$info.is_lock}">
                    <input type="hidden" name="head_pic" id="head_pic" value="{$info.head_pic}">
                    <input type="hidden" name="scores" id="scores" value="{$info.scores|default=0}">
                    <input type="hidden" name="users_money" id="users_money" value="{$info.users_money|default=0}">
                    <div class="order-list">
                        <div class="list-left">头像</div>
                        <div class="list-right">
                            <div class="display-f-r">
                                <div class="users-pic">
                                    <img src="{$info.head_pic|get_head_pic=###,false,$info['sex']}">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="order-list">
                        <div class="list-left">会员昵称</div>
                        <div class="list-right">
                            <div class="ey-input">
                                <div class="ey-input-wrapper">
                                    <input type="text" name="nickname" id="nickname" value="{$info.nickname|html_msubstr=###,0,20,true}" maxlength="140" enterkeyhint="done" autocomplete="off" class="ey-input-input">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="order-list">
                        <div class="list-left">会员编码</div>
                        <div class="list-right">
                            <div class="text">{$info['users_id']|sprintf='%08d',###}</div>
                        </div>
                    </div>
                    <!-- <div class="order-list">
                        <div class="list-left">会员名称</div>
                        <div class="list-right">
                            <span class="mr10">{$info.username}</span>
                        </div>
                    </div> -->
                    <div class="order-list">
                        <div class="list-left">关注状态</div>
                        <div class="list-right">
                            <div class="text" id="weChatSubscribe"><!-- 检测中... --></div>
                        </div>
                    </div>
                    <script type="text/javascript">
                        $(function() {
                            var open_id = '{$info.open_id}';
                            if (open_id) {
                                $.ajax({
                                    type: 'post',
                                    url : "{:url('Ajax/getWeChatSubscribe')}",
                                    data: {open_id: open_id, '_ajax': 1},
                                    dataType: 'json',
                                    success: function (res) {
                                        console.log(res)
                                        layer.closeAll();
                                        if (1 === parseInt(res.code)) $('#weChatSubscribe').empty().html(res.data);
                                    }
                                });
                            } else {
                                $('#weChatSubscribe').empty().html('未关注');
                            }
                        });
                    </script>
                    <div class="order-list">
                        <div class="list-left">会员来源</div>
                        <div class="list-right">
                            <div class="display-f-r">
                                <div class="users-source">
                                    <i class="iconfont icon-ly-gzh {eq name='$info.source' value='3'}yes{/eq}"></i>
                                </div>
                                <div class="users-source">
                                    <i class="iconfont icon-ly-wxxcx {eq name='$info.source' value='4'}yes{/eq}"></i>
                                </div>
                                <div class="users-source">
                                    <i class="iconfont icon-ly-bd {eq name='$info.source' value='5'}yes{/eq}"></i>
                                </div>
                                <div class="users-source">
                                    <i class="iconfont icon-ly-dy {eq name='$info.source' value='6'}yes{/eq}"></i>
                                </div>
                                <div class="users-source">
                                    <i class="iconfont icon-ly-pc {eq name='$info.source' value='1'}yes{/eq}"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="order-list">
                        <div class="list-left">登录密码</div>
                        <div class="list-right">
                            <div class="ey-input">
                                <div class="ey-input-wrapper">
                                    <input type="text" name="password" id="password" autocomplete="off" class="ey-input-input" placeholder="不修改留空">
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 自定义字段 -->
                    {notempty name='$users_para'}
                    {include file="member/users_field"/}
                    {/notempty}
                    <!-- 自定义字段 - end -->
                    <div class="order-list" {if condition="empty($usersConfig['level_member_upgrade'])"} style="display: none;" {/if}>
                        <div class="list-left">会员等级</div>
                        <div class="list-right">
                            <div class="select">
                                <select name="level" id="level" onchange="mobileIsOpenDays(this);">
                                    {volist name='$level' id='vo'}
                                    <option value="{$vo.level_id}" {eq name="$info.level" value="$vo.level_id" } selected {/eq}>{$vo.level_name}</option>
                                    {/volist}
                                </select>
                            </div>
                            <i class="iconfont icon-right"></i>
                        </div>
                    </div>
                    {if condition="1 == $usersConfig.level_member_upgrade"}
                    <div class="order-list" {eq name="$info.level" value="1"} style="display: none;" {/eq} id="users_days">
                        <div class="list-left">会员天数</div>
                        <div class="list-right">
                            <div class="ey-input">
                                <div class="ey-input-wrapper">
                                    <input type="text" name="level_maturity_days_up" id="level_maturity_days" value="{$info.level_maturity_days_new|default='0'}" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\[^0-9]/g,''));" maxlength="10" class="ey-input-input">
                                </div>
                            </div>
                        </div>
                        <input type="hidden" id="level_member_upgrade" value="1">
                        <input type="hidden" name="level_maturity_days_old" value="{$info.level_maturity_days}">
                        <input type="hidden" name="level_maturity_days_new" value="{$info.level_maturity_days_new}">
                    </div>
                    {/if}
                    <div class="order-list">
                        <div class="list-left">注册时间</div>
                        <div class="list-right">
                            <div class="text">{$info.reg_time|date='Y-m-d H:i:s',###}</div>
                        </div>
                    </div>
                    <div class="order-list">
                        <div class="list-left">最后登录</div>
                        <div class="list-right">
                            <div class="text">{$info.last_login|date='Y-m-d H:i:s',###}</div>
                        </div>
                    </div>
                    <div class="order-list">
                        <div class="list-left">注册 IP</div>
                        <div class="list-right">
                            <div class="text">{notempty name="$info.reg_ip_val"}{$info.reg_ip_val}({$info.reg_ip_text}){/notempty}</div>
                        </div>
                    </div>
                </form>
                <div class="footer-wrap" style="position:unset;border:none">
                    <div class="container" style="margin: 0;">
                        {eq name='$info.is_lock' value='-1'}
                        <button class="nt" onclick="changeIsLock(this);" data-value="0">恢复发言</button>
                        {/eq}
                        {eq name='$info.is_lock' value='-99'}
                        <button class="nt" onclick="changeIsLock(this);" data-value="0">移除黑名单</button>
                        {else/}
                        <button class="nt" onclick="changeIsLock(this);" data-value="-99">加入黑名单</button>
                        {/eq}
                        <!-- <button class="nt" data-url="{:url('Member/users_del')}" data-id="{$info.users_id}" data-admin_id="{$info.admin_id}" data-username="{$info.username}" onClick="mobileUsersDel(this);">删除</button> -->
                    </div>
                </div>
            </div>
        </div>

        <div class="item-wrap-box">
            <div class="item-wrap">
                <div class="order-list">
                    <div class="list-left">用户余额</div>
                    <div class="list-right">
                        <div class="ey-input">
                            <div class="ey-input-wrapper">
                                <input type="text" value="{$info.users_money|default=0}" maxlength="140" enterkeyhint="done" autocomplete="off" class="ey-input-input" onpaste="this.value=this.value.replace(/[\。]/g,'.');this.value=this.value.replace(/[^\d.]/g, '');" onkeyup="this.value=this.value.replace(/[\。]/g,'.');this.value=this.value.replace(/[^\d.]/g, ''); synchronizeValue(this, 'users_money');">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="order-list">
                    <div class="list-left">用户积分</div>
                    <div class="list-right">
                        <div class="ey-input">
                            <div class="ey-input-wrapper">
                                <input type="text" value="{$info.scores|default=0}" maxlength="10" enterkeyhint="done" autocomplete="off"  class="ey-input-input" onpaste="this.value=this.value.replace(/[^\d]/g, '');" onkeyup="this.value=this.value.replace(/[^\d]/g, ''); synchronizeValue(this, 'scores');">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="item-wrap-box">
            <div class="form-title">订单交易</div>
            <div class="item-wrap">
                <div class="order-list">
                    <div class="list-left">累计订单数</div>
                    <div class="list-right">
                        <span class="mr10">{$order_count.0.count|default=0}笔</span>
                    </div>
                </div>
                <div class="order-list">
                    <div class="list-left">累计成交额</div>
                    <div class="list-right">
                        <span class="mr10">￥{$order_count.0.sum|default=0}</span>
                    </div>
                </div>
            </div>
            <div class="form-title">退款订单</div>
            <div class="item-wrap">
                <div class="order-list">
                    <div class="list-left">累计退款数</div>
                    <div class="list-right">
                        <span class="mr10">{$refund_count.0.count|default=0}笔</span>
                    </div>
                </div>
                <div class="order-list">
                    <div class="list-left">累计退款额</div>
                    <div class="list-right">
                        <span class="mr10">￥{$refund_count.0.sum|default=0}</span>
                    </div>
                </div>
            </div>
        </div>

        <div class="w100-footer-wrap">
            <button class="" onclick="checkForm();">保存</button>
        </div>
    </div>
    <script type="text/javascript">
        $('.tab-wrap .tab-item').on('click', function () {
            $(this).addClass('active').siblings().removeClass('active');
            $('.item-wrap-box').hide().eq($('.tab-wrap .tab-item').index(this)).show();
        });

        // 实时同步更新页面上指定字段值
        function synchronizeValue(obj, name) {
            var value = $(obj).val() ? $(obj).val() : 0;
            $('#' + name).val(value);
        }

        // 手机端会员删除
        function mobileUsersDel(obj) {
            var admin_id = $(obj).data('admin_id');
            if (0 < admin_id) {
                var content = "系统管理员前台ID，删除不可恢复？<br/>包含该会员数据有(订单、投稿、问答、留言等)";
            } else {
                var content = "确认彻底删除？<br/>包含该会员数据有(订单、投稿、问答、留言等)";
            }
            // 提示确认
            layer.open({content: content, btn: ['确定', '取消'], skin: 'footer',
                yes: function(index) {
                    // 提示处理
                    layerLoading();
                    // 提交处理
                    $.ajax({
                        url : $(obj).attr('data-url'),
                        data: {
                            _ajax: 1,
                            weappAjax: 1,
                            del_id: $(obj).attr('data-id'),
                        },
                        type: 'post',
                        dataType: 'json',
                        success: function(res) {
                            layer.closeAll();
                            if (1 == res.code) {
                                layerMsg(res.msg, 1, function() {
                                    window.location.href = "{:url('Member/users_index')}";
                                });
                            } else {
                                layerAlert(res.msg, '确认');
                            }
                        }
                    });
                }
            });
        }

        // 手机端会员级别
        function mobileIsOpenDays(obj) {
            if (1 == $('#level_member_upgrade').val()) {
                var exptime = 0;
                var level_id = $(obj).val();
                if (1 == level_id) {
                    $('#users_days').css('display', 'none');
                    $('#level_maturity_days').val(exptime);
                } else {
                    // 提交处理
                    $.ajax({
                        type: 'post',
                        url : "{:url('Member/query_level_days')}",
                        data: {
                            _ajax: 1,
                            weappAjax: 1,
                            level_id: level_id,
                        },
                        dataType: 'json',
                        success: function(res) {
                            layer.closeAll();
                            if (res.code == 1) {
                                exptime = parseInt(res.data);
                                $('#level_maturity_days').val(exptime);
                            } else {
                                layerAlert(res.msg, '确认');
                            }
                        }
                    });
                    $('#users_days').css('display', '');
                    $('#level_maturity_days').css('border-bottom', 'solid 1px rgba(51,152,204,0.8)').focus();
                }
            }
        }

        // 加入黑名单/移除黑名单/恢复发言
        function changeIsLock(obj) {
            var value = $(obj).attr('data-value');
            $('#is_lock').val(value);
            if (-99 == value) {
                var content = "加入黑名单将限制以下功能：<br/>1.禁止会员中心全部数据的提交。<br/>2.禁止问答发帖/回帖等数据提交。";
                // 提示确认
                layer.open({content: content, btn: ['确定', '取消'], skin: 'footer',
                    yes: function(index) {
                        checkForm();
                    }
                });
            } else {
                checkForm();
            }
        }

        // 判断输入框是否为空
        function checkForm() {
            if (1 == $('#level_member_upgrade').val()) {
                if (1 != $('#level').val() && (!$('#level_maturity_days').val() || 0 == $('#level_maturity_days').val())) {
                    layerMsg('请填写会员有效期天数！', 1);
                    $('#level_maturity_days').focus();
                    return false;
                }
            }
            // 提示处理
            layerLoading();
            // 提交处理
            $.ajax({
                type: 'post',
                url : "{:url('Member/users_edit')}",
                data: $('#postForm').serialize(),
                dataType: 'json',
                success: function(res) {
                    layer.closeAll();
                    if (1 == res.code) {
                        layerMsg(res.msg, 1, function() {
                            window.location.reload();
                        });
                    } else {
                        layerAlert(res.msg, '确认');
                    }
                }
            });
        }
    </script>
</body>
{include file="public/footer.htm" /}